var app = getApp();
import demodata from './data';
import routerConfig from './router';
import routerInit from 'miniapp-router';

Page({
  data: {
    demodata,
    typeName: '活动设置',
    componentName: '首页',
    type: 'component',
    component: 'home',
    selectedKeys: ['home'],
    user_name: '浪子arvin',
    modalVd:true
  },
  onLoad() {
    routerInit.call(this, routerConfig);
    //从缓存里面拿用户名
    var that = this;
    my.getStorage({
      key: 'users',
      success: function (res) {
        if (res.data) {
          that.setData({
            user_name: res.data.user_name
          })
        } else {
          app.getAuth();
        }
      },
      fail: function (res) {
        app.getAuth();
      }
    });
  },
  // 退出登录
  userOut(id) {
    console.log(id);
    //  var app = getApp();
    // my.setStorage({
    //   key: 'users',
    //   data: {
    //     user_name: ''
    //   },
    //   success: function () {
    //     app.getAuth();
    //     // my.alert({ content: '写入成功' });
    //   }
    // });
  },
  onItemClick(event) {
    console.log(event)
    let { typeName, componentName, type, component } = event.target.dataset;
    this.setData({ typeName, componentName, type, component });
    
    if (`/${type}/${component}` === '/adaptive/framework') {
      my.navigateTo({ url: '/page/adaptive/adaptive' });
      return;
    }
    this.$router.push(`/${type}/${component}`);
    console.log('[router test]：', `/${type}/${component}`);
  },
  handleSelect(value) { },
});
